# -*- coding: utf-8 -*-
from google.appengine.ext import db
from google.appengine.ext import search  

class Category(db.Model):
    name = db.StringProperty()
    post_count = db.IntegerProperty(default=0)
    #logo = db.StringProperty()
    
    def __str__(self):
        return self.name

class Door(search.SearchableModel):
    #author = db.UserProperty()
    
    #Base Properity for Door
    title = db.TextProperty(required=True, verbose_name=u'标题')
    tag = db.StringProperty(verbose_name=u'标签')
    content = db.TextProperty(required=True, verbose_name=u'内容')
    create_time = db.DateTimeProperty(auto_now_add=True)
    update_time = db.DateTimeProperty(auto_now=True)
    #category = db.ReferenceProperty(Category, required=True, verbose_name=u'类别')
    
    #The Story
    
    is_published = db.BooleanProperty(verbose_name=u'已发布')
    comment_count = db.IntegerProperty(default=0)
    read_count = db.IntegerProperty(default=0)
    
    def get_absolute_url(self) :
        return '/door/%s/'%self.key().id()
    
    
    
class Comment(db.Model):
    author = db.UserProperty()
    post = db.ReferenceProperty(Door)
    content = db.StringProperty(multiline=True)
    create_time = db.DateTimeProperty(auto_now_add=True)

class Person():
    aboutMe = db.StringProperty()
    
    
class Story(search.SearchableModel):
    time_range = db.DateTimeProperty(required=True, verbose_name=u'时间')
    address = db.StringProperty(required=True, verbose_name=u'地点')
    key_person = db.ReferenceProperty(Person, required = True, verbose_name = u'人物')
    
    reson = db.StringProperty(required=True, verbose_name=u'缘起')
    content = db.StringProperty(required=True, verbose_name=u'经过')
    end = db.StringProperty(required=True, verbose_name=u'结果')
    
